<!doctype html>
<html lang="en-us">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>JavaScript transitions demo</title>
    <style>
      body {
        background-color: #fff;
        color: #333;
        font:
          1.2em / 1.5 Helvetica Neue,
          Helvetica,
          Arial,
          sans-serif;
        padding: 0;
        margin: 0;
      }

      h1 {
        font-size: 1.2em;
      }

      main {
        box-sizing: border-box;
        display: flex;
        justify-content: center;
        align-items: center;
        max-width: 660px;
        height: 400px;
        border: 1px solid #ccc;
        padding: 20px;
      }

      .ball {
        border-radius: 25px;
        width: 50px;
        height: 50px;
        background: #c00;
        position: absolute;
        top: 0;
        left: 0;
        transition: transform 1s;
      }
    </style>
  </head>
  <body>
    <main>
      <h1>Click anywhere to move the ball</h1>
      <div id="foo" class="ball"></div>
    </main>
  </body>
  <script>
    var f = document.getElementById("foo");
    document.addEventListener(
      "click",
      function (ev) {
        f.style.transform = "translateY(" + (ev.clientY - 25) + "px)";
        f.style.transform += "translateX(" + (ev.clientX - 25) + "px)";
      },
      false,
    );
  </script>
</html>
